#include "EXTERN.h"
#include "perl.h"
#include "XSUB.h"
#include <stdlib.h>
#include "ppport.h"

#include "const-c.inc"

#include "trans/mylib.h"
#include "trans/slowo2.h"
#include "trans/slowo3.h"
#include "trans/semantika.h"
#include "trans/grammar.h"
#include "trans/core.h"


MODULE = Prawda		PACKAGE = Prawda		

INCLUDE: const-xs.inc

SV*
read_grammar(char *prawdadir,char *dir,char *name)
	INIT:

	CODE: 

	    char *s1,*s, r, *Sou, *Dst;
	    t_DirTrans* DirTrans=(t_DirTrans*)Calloc(2,sizeof(t_DirTrans));
	    s1=(char*)Calloc(strlen(dir)+1,sizeof(char));
	    strcpy(s1,dir);
	    DirTrans[0].Dir=s1;
	    s1=(char*)Calloc(strlen(name)+1,sizeof(char));
	    strcpy(s1,name);
	    DirTrans[0].Name=s1;
	    
	    
	    
	    r=read_grammar(prawdadir,DirTrans);
	    if (r<0) { 
		s1=(char*)Calloc(strlen("error\n")+1,sizeof(char));
		strcpy(s1,"error\n");

	    }else{ 
	    	s1=(char*)Calloc(strlen("that's ok!\n")+1,sizeof(char));
		strcpy(s1,"that's ok!\n");

	    }

		
	    HV* hash = newHV();
	    AV* array = newAV();
	    av_push(array, newSVnv(34));
	    av_push(array, newSVnv(77));
	    hv_store(hash, "lang_name",9, newSVpv((char*)s1, strlen(s1)*sizeof('a')),0);
	    hv_store(hash, "array",5, (SV*)array,0);
	RETVAL=newRV( (SV*) hash);

	
	OUTPUT:
	    RETVAL


int
hello() 
	INIT:

	CODE: 
		Core.init(10,10);
		Core.hello();
	OUTPUT:
	RETVAL


SV*
translate ( char * Sou) 
	INIT:

	CODE: 
	    char *s1,*Dst;
		
	    Core.init(100,100);


	    s1=(char*)Calloc(strlen(Sou)+1,sizeof(char));
	    strcpy(s1,Sou);

	    Dst=(char*)Calloc(2*strlen(Sou)+1,sizeof(char));
	    Core.translate(Sou,Dst);
	    
	    s1=(char*)Calloc(strlen(Dst)+1,sizeof(char));
	    strcpy(s1,Dst);
		
	    HV* hash = newHV();
	    AV* array = newAV();
	    av_push(array, newSVnv(34));
	    av_push(array, newSVnv(77));
	    hv_store(hash, "lang_name",9, newSVpv((char*)s1, strlen(s1)*sizeof('a')),0);
	    hv_store(hash, "array",5, (SV*)array,0);
	RETVAL=newRV( (SV*) hash);

	
	OUTPUT:
	    RETVAL

